package com.xinruke.hostels.manage.user.controller.pms;

import com.xinruke.hostels.common.cache.ManageUserCache;
import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.po.XtJuese;
import com.xinruke.hostels.common.service.OperateLogService;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.manage.user.interfaces.dto.RoleAddDTO;
import com.xinruke.hostels.manage.user.interfaces.dto.RoleQueryDTO;
import com.xinruke.hostels.manage.user.interfaces.dto.RoleQueryResultDTO;
import com.xinruke.hostels.manage.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @ClassName RoleController
 * @CreateDate 2019/6/13
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 角色管理
 */
@RestController
@RequestMapping("role/pms")
@Api(tags = "PMS角色管理")
public class RolePMSController extends BaseController {
    @Resource
    private RoleService roleService;
    @Resource
    OperateLogService operateLogService;

    @Resource
    ManageUserCache manageUserCache;


    @PostMapping(value = "/add")
    @ApiOperation(value = "添加角色")
    public ResultVO addUserInfo(@Valid @RequestBody RoleAddDTO roleAddDTO) {
        ResultVO resultVO = ResultVO.fail();
        roleAddDTO.setJiudianId(manageUserCache.getJiudianId());
        roleAddDTO.setSuoshuxitong(XtJuese.SUOSHUXITONG_PMS);

        int n = roleService.add(roleAddDTO);

        if (n > 0) {
            operateLogService.writeOperateLog("PMS角色管理", "添加角色", "名称[" + roleAddDTO.getMingcheng() + "]");

            resultVO.setCode(ResultVO.SUCCESS);
            resultVO.setMessage("操作成功");
        }
        return resultVO;
    }


    @PostMapping(value = "/list")
    @ApiOperation(value = "查询当前酒店角色和使用用户数")
    public ResultVO<RowsDataVO<RoleQueryResultDTO>> getRoleList(@Valid @RequestBody RoleQueryDTO roleQueryDTO) {
        ResultVO<RowsDataVO<RoleQueryResultDTO>> resultVO = ResultVO.fail();
        roleQueryDTO.setJiudianId(manageUserCache.getJiudianId());
        RowsDataVO<RoleQueryResultDTO> data = roleService.getRoleList(roleQueryDTO);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(data);

        return resultVO;
    }
}
